package com.sanjiahantang.youjiarole.module.common.holders;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.sanjiahantang.uilibrary.adapter.listview.BaseAdapterHelper;
import com.sanjiahantang.uilibrary.adapter.listview.QuickAdapter;
import com.sanjiahantang.uilibrary.utils.Utils;
import com.sanjiahantang.uilibrary.views.MyListView;
import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.config.StaticValue;
import com.sanjiahantang.youjiarole.module.cases.beans.CaseBean;
import com.sanjiahantang.youjiarole.module.cases.views.impl.CaseActivity;
import com.sanjiahantang.youjiarole.module.cases.views.impl.CaseDetailActivity;
import com.sanjiahantang.youjiarole.module.goods.beans.GoodsBean;
import com.sanjiahantang.youjiarole.module.match.views.impl.MatchListActivity;
import com.sanjiahantang.youjiarole.module.store.beans.StoreBean;
import com.sanjiahantang.youjiarole.module.store.views.impl.StoreActivity;
import com.sanjiahantang.youjiarole.utils.FileUtils;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/6/8.
 * 新品上市，热销商品，家用电器的ViewHolder
 */

public class ComprehensiveHolder extends MyBaseViewHolder implements View.OnClickListener ,StaticValue{
    //三种标识
    private int type;
    private String currentType;
    private final int TYPE_CASE = 3;//案例
    private final int TYPE_NEARSTORE=4;//附近体验店
    public static final int TYPE_MATCH_TITLE = 5;//搭配标题
    public static final int TYPE_MATCH = 6;//搭配

    private String name,enName;
    private Context context;
    private TextView tv_type, tv_more,tvEnglish;
    private MyListView lv_comprehen;
    private View rootView;

    private Object data;

    //这里只需要显示前几个就行
    private List<GoodsBean.Data> partDatas = new ArrayList<>();

    public ComprehensiveHolder(View itemView, final int type, final Context context, Object data, final String name, final String enName) {
        super(itemView);

        this.type = type;
        this.context = context;
        this.data = data;
        this.name = name;
        this.enName = enName;

        tv_type = (TextView) itemView.findViewById(R.id.tv_type);
        tv_more = (TextView) itemView.findViewById(R.id.tv_more);
        lv_comprehen = (MyListView) itemView.findViewById(R.id.lv_comoerhensive);
        tvEnglish = (TextView) itemView.findViewById(R.id.tv_comprehensive_en);
        rootView = itemView.findViewById(R.id.rootView);
    }

    @Override
    public void bindData() {
        tv_type.setText(name);
        tvEnglish.setText(enName);
        tv_more.setOnClickListener(this);
        switch (type){
            case TYPE_CASE:
                rootView.setBackgroundColor(context.getResources().getColor(R.color.white));
                initCases((List<CaseBean.Item>)data);
                break;
        }
    }



    private void initCases(List<CaseBean.Item> cdata) {
        QuickAdapter<CaseBean.Item> quickAdapter = new QuickAdapter<CaseBean.Item>(context,R.layout.item_main_case) {
            @Override
            protected void convert(BaseAdapterHelper helper, final CaseBean.Item item) {
                helper.setText(R.id.txtCaseTitle,item.getCaseTitle());
                helper.setText(R.id.txtDesignerName,"设计师:  " + item.getUserName());
                Picasso.with(context).load(FileUtils.rePath(item.getHeadImg())).placeholder(R.drawable.i_head_default).into((ImageView) helper.getView(R.id.ivDesignerPhoto));
                Picasso.with(context).load(FileUtils.rePath(item.getCaseImg())).placeholder(R.drawable.i_match).into((ImageView) helper.getView(R.id.ivCaseMain));
                helper.setOnClickListener(R.id.ivCaseMain, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        context.startActivity(new Intent(context, CaseDetailActivity.class)
                                .putExtra("param",item.getResidentialName())
                                .putExtra(KEY_ID,item.getId())
                        );
                    }
                });
            }
        };
        quickAdapter.addAll(cdata);
        lv_comprehen.setAdapter(quickAdapter);

    }

    @Override
    public void onClick(View v) {
        switch (type){
            case TYPE_CASE:
                context.startActivity(new Intent(context, CaseActivity.class));
                break;
            case TYPE_NEARSTORE:
                context.startActivity(new Intent(context, StoreActivity.class));
                break;
            case TYPE_MATCH_TITLE:
                context.startActivity(new Intent(context, MatchListActivity.class));
                break;
        }
    }
}
